// initial state
// shape: [{ id, quantity }]
const state = {
  data: []
}

// getters
const getters = {
  getData: (state, instanceId, propId) => {
    if (typeof state.data[instanceId] === 'undefined') {
      state.data[instanceId] = {}
    }

    if (typeof state.data[instanceId][propId] === 'undefined') {
      return null
    }

    return state.data[instanceId][propId]
  }
}

// actions
const actions = {}

// mutations
const mutations = {
  init (state, instanceId) {
    state.data[instanceId] = {}
  },
  setData (state, {instanceId, propId, value}) {
    if (!state.data[instanceId]) {
      state.data[instanceId] = {}
    }

    state.data[instanceId][propId] = value
    state.data = {...state.data} // 使用克隆对象的方式更新才能出发刷新机制

    // console.log(`commit:${instanceId}:${propId}:${value}`)
  }
}

export default {
  namespaced: true,
  state,
  getters,
  actions,
  mutations
}
